/**
 * 
 */
package com.hp.sso.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.web.servlet.View;

import com.hp.sso.MyConnectView;
import com.hp.sso.qq.connet.QQConnectionFactory;

/**
 * @author hp
 *
 */
@Configuration
@Order(2)
@ConditionalOnProperty(prefix = "qq", name = "app-id")  //按需加载 当配置文件有 qq.app-id才会加载此配置
public class QQAutoConfig extends SocialAutoConfigurerAdapter {
	
	@Value("${qq.providerId}")
	private String providerId;
	
	@Value("${qq.app-id}")
	private String appId;
	
	@Value("${qq.app-secret}")
	private String appSecret;
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter
	 * #createConnectionFactory()
	 */
	@Override
	protected ConnectionFactory<?> createConnectionFactory() {
		return new QQConnectionFactory(providerId, appId, appSecret);
	}

	@Bean({"connect/qqConnect", "connect/qqConnected"})
	@ConditionalOnMissingBean(name = "qqConnectedView")
	public View qqConnectedView() {
		return new MyConnectView();
	}

	public String getProviderId() {
		return providerId;
	}


	public void setProviderId(String providerId) {
		this.providerId = providerId;
	}


	public String getAppId() {
		return appId;
	}


	public void setAppId(String appId) {
		this.appId = appId;
	}


	public String getAppSecret() {
		return appSecret;
	}


	public void setAppSecret(String appSecret) {
		this.appSecret = appSecret;
	}
}
